package java101;

//Import Java programs
import java.util.Scanner;
import javax.swing.JOptionPane;

public class TempConverterPartFour {

	static Scanner sc = new Scanner(System.in);		
	public static void main(String[] args)				
	{
		//Declare the variables
		double finalTemp;
		String degString;
		
		//Display and get the text and input data
		degString = JOptionPane.showInputDialog
			("Enter the temperature, prefixed by 'c' or 'f': ");


		if (degString.startsWith("f")) {
			String degNoLetter = degString.substring(1);
			double degDouble = Double.parseDouble(degNoLetter); //Changes the input to a double and removes the first letter
			double mathStepOne;
			double fiveOverNine = (double) 5/9;
			
			mathStepOne = (double) degDouble - 32;
			finalTemp = (double) fiveOverNine * mathStepOne; //Performs the math
			
			String answer;
			answer = String.format("%.2f deg F = %.2f deg C", degDouble, finalTemp);
			
			JOptionPane.showMessageDialog(null, answer); //Display the result
		}
		else if (degString.startsWith("c")) {
			String degNoLetter = degString.substring(1);
			double degDouble = Double.parseDouble(degNoLetter);
			
			finalTemp = (double) 9 * degDouble / 5 + 32;
			
			String answer;
			answer = String.format("%.2f deg C = %.2f deg F", degDouble, finalTemp);
			
			JOptionPane.showMessageDialog(null, answer);	
		}
		else {
			JOptionPane.showMessageDialog(null, "Please prefix your number by 'c' or 'f'!");
		}
				
	
	}

}

